package com.baibei.ebec;

import android.os.Build;
import android.os.StrictMode;

import com.baibei.module.AppRouter;
import com.baibei.module.BuildConfig;
import com.baibei.module.EBECBasicApplication;
import com.mob.MobSDK;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by shenminjie on 2017/8/2 14:06.
 * mail:shenminjie@100bei.com
 */

public class ECommerceApplication extends EBECBasicApplication {

    @Override
    public void onCreate() {
        if (BuildConfig.DEBUG) {
            AppRouter.debug();
        }
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            builder.detectFileUriExposure();
        }
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        MobSDK.init(this);
        closeAndroidPDialog();
        super.onCreate();
    }

    private void closeAndroidPDialog(){
        try {
            Class aClass = Class.forName("android.content.pm.PackageParser$Package");
            Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
            declaredConstructor.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Class cls = Class.forName("android.app.ActivityThread");
            Method declaredMethod = cls.getDeclaredMethod("currentActivityThread");
            declaredMethod.setAccessible(true);
            Object activityThread = declaredMethod.invoke(null);
            Field mHiddenApiWarningShown = cls.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
